package com.springcloud.store.modular.product.controller;

import com.springcloud.commom.annotion.BusinessLog;
import com.springcloud.commom.api.R;
import com.springcloud.commom.enums.LogAnnotionOpTypeEnum;
import com.springcloud.stock.param.ProductParam;
import com.springcloud.store.modular.product.service.ProductService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 商品表控制器
 *
 * @author hzl
 * @date 2024-07-26 10:42:06
 */
@RestController
public class ProductController {

    @Resource
    private ProductService productService;

    /**
     * 查询商品表
     *
     * @author hzl
     * @date 2024-07-26 10:42:06
     */
    @GetMapping("/product/page")
    @BusinessLog(title = "商品表_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public R page(ProductParam productParam) {
        return R.data(productService.page(productParam));
    }

    /**
     * 添加商品表
     *
     * @author hzl
     * @date 2024-07-26 10:42:06
     */
    @PostMapping("/product/add")
    @BusinessLog(title = "商品表_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public R add(@RequestBody @Validated(ProductParam.add.class) ProductParam productParam) {
        productService.add(productParam);
        return R.success();
    }

    /**
     * 删除商品表
     *
     * @author hzl
     * @date 2024-07-26 10:42:06
     */
    @PostMapping("/product/delete")
    @BusinessLog(title = "商品表_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public R delete(@RequestBody @Validated(ProductParam.delete.class) ProductParam productParam) {
        productService.delete(productParam);
        return R.success();
    }

    /**
     * 编辑商品表
     *
     * @author hzl
     * @date 2024-07-26 10:42:06
     */
    @PostMapping("/product/edit")
    @BusinessLog(title = "商品表_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public R edit(@RequestBody @Validated(ProductParam.edit.class) ProductParam productParam) {
        productService.edit(productParam);
        return R.success();
    }

    /**
     * 查看商品表
     *
     * @author hzl
     * @date 2024-07-26 10:42:06
     */
    @GetMapping("/product/detail")
    @BusinessLog(title = "商品表_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
    public R detail(@Validated(ProductParam.detail.class) ProductParam productParam) {
        return R.data(productService.detail(productParam));
    }

    /**
     * 商品表列表
     *
     * @author hzl
     * @date 2024-07-26 10:42:06
     */
    @GetMapping("/product/list")
    @BusinessLog(title = "商品表_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public R list(ProductParam productParam) {
        return R.data(productService.list(productParam));
    }

}
